<template>
  <Modal v-model="confirmModal" :mask-closable="false" width="360">
    <p slot="header" style="text-align: center; color: red">
      <Icon type="ios-information-circle"></Icon>
      <span>{{ action.title }} 确认</span>
    </p>
    <div style="text-align: left">
      <p>您即将对</p>
      <p>
        工单ID: <span style="color: red">{{ orderInfo.id }}</span>
      </p>
      <p>
        工单描述: <span style="color: red">{{ orderInfo.description }}</span>
      </p>
      <p>
        工单类型: <span style="color: red">{{ orderInfo.orderType }}</span>
      </p>
      <p>
        DB类型: <span style="color: red">{{ orderInfo.dbType }}</span>
      </p>
      <p>
        DB集群: <span style="color: red">{{ orderInfo.dbClusterName }}</span>
      </p>
      <p>
        DB Database: <span style="color: red">{{ orderInfo.dbDatabase }}</span>
      </p>
      <p>
        DB Table: <span style="color: red">{{ orderInfo.dbTable }}</span>
      </p>
      <p>
        申请人: <span style="color: red">{{ orderInfo.createBy }}</span>
      </p>
      <p>
        执行<span style="color: red"> {{ action.title }} </span>操作
      </p>
      <p>确定执行该操作吗?</p>
    </div>
    <div slot="footer">
      <Button type="success" size="large" :loading="loading" @click="ok">确认</Button>
      <Button type="default" size="large" @click="cancel">取消</Button>
    </div>
  </Modal>
</template>

<script>
import { updateTicketOrder } from '@/api/ticket/order'
import { errorNotify } from '@/libs/util'
import { snakeCaseObject } from '@/libs/object'

export default {
  name: 'ConfirmModal',
  props: {
    confirmModal: {
      type: Boolean,
      default: false,
      require: true
    },
    orderInfo: {
      type: Object,
      require: true,
      default() {
        return {}
      }
    },
    action: {
      type: Object,
      require: true,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      loading: false
    }
  },
  computed: {},
  mounted() {},
  created() {},
  methods: {
    ok() {
      this.loading = true
      this.updateTicketOrder()
    },
    cancel() {
      this.$emit('on-order-delete', { type: 'cancel', status: false })
    },
    async updateTicketOrder() {
      const params = {
        status: this.action.type
      }
      try {
        await updateTicketOrder(this.orderInfo.id, snakeCaseObject(params))
        this.loading = false
        this.$Notice.success({ title: this.action.title + ' 工单: ' + this.orderInfo.id + '成功' })
        this.$emit('on-order-confirm', { type: 'confirm', status: false })
      } catch (e) {
        errorNotify(e)
      }
    }
  }
}
</script>

<style scoped></style>
